﻿using CPPEI.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestTCPContract
{
    public class DrawReq
    {
        /// <summary>
        /// 32
        /// </summary>
        [CPPEI.Net.Field(Order = 1, Length = 32)]
        public string Message { get; set; }

        /// <summary>
        /// 4
        /// </summary>
        [CPPEI.Net.Field(Order = 2)]
        public int Value { get; set; }

        [Field(Order = 3, Length = 102400)]
        public byte[] Data { get; set; }

        public static byte[] ToData(DrawReq req)
        {
            byte[] data = new byte[36];
            int offset = 0;
            CPPEI.Net.BufferUtil.StringToBuffer(req.Message, data, ref offset, 32);
            CPPEI.Net.BufferUtil.IntToBuffer(req.Value, data, ref offset);

            return data;
        }

        public static DrawReq FromData(byte[] data)
        {
            DrawReq req = new DrawReq();
            int offset = 0;
            req.Message = CPPEI.Net.BufferUtil.StringFromBuffer(data, ref offset, 32);
            req.Value = CPPEI.Net.BufferUtil.IntFromBuffer(data, ref offset);
            return req;
        }
    }
}
